package com.pesilo.mvc.view.component.module.backgroundModule
{
	
	
	import com.pesilo.base.BaseComponent;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;

	public class ImgComponent extends BaseComponent
	{
		private var str:String;
		private var loader:Loader;
		private var mc:Sprite;
		private var bitmap:Bitmap;
		private var scaleNum:Number = 0.2;
		
		public function ImgComponent(str:String)
		{
			this.str=str;
		}
		override public function initUI():void{
			mc=new Sprite();
			this.addChild(mc);
			
			loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,__loaderCompleteHandle);
			loader.load(new URLRequest(str));
		}
		
		protected function __loaderCompleteHandle(e:Event):void
		{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,__loaderCompleteHandle);
			bitmap=loader.content as Bitmap;
			mc.addChild(bitmap);
		}
		
		public function setBitSize(bitmap:Bitmap):void {
			var w:Number = stage.stageWidth*(1+scaleNum);
			var h:Number = stage.stageHeight * (1 + scaleNum);
			if ((bitmap.width / bitmap.height) < (w / h)) {
				bitmap.height = bitmap.height * w / bitmap.width;
				bitmap.width =w;
			}else {
				bitmap.width = bitmap.width * h / bitmap.height;
				bitmap.height = h;
			}
		}
		
		override public function initLocation():void {
			if(bitmap){
				setBitSize(bitmap);
			}
		}
	}
}